package www.ym.com.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import www.ym.com.entity.Dish;
import www.ym.com.entity.DishFlavor;
import www.ym.com.mapper.DishFlavorMapper;
import www.ym.com.service.DishFlavorService;


@Slf4j
@Service
public class DishFlavorServiceImpl extends ServiceImpl<DishFlavorMapper, DishFlavor> implements DishFlavorService {


    @Autowired
    private DishFlavorMapper dishFlavorMapper;

    @Override
    public Page<DishFlavor> pageFlavor(JSONObject jsonObject) {
        Long pageNum = Long.valueOf(String.valueOf(jsonObject.get("pageNum")));
        //每页显示数
        Long pageSize = Long.valueOf(String.valueOf(jsonObject.get("pageSize")));
        //口味名称
        String name = String.valueOf(jsonObject.get("name"));
//        //分类类别
//        String type = String.valueOf(String.valueOf(jsonObject.get("type")));
        log.info("当前页为" + pageNum);
        log.info("每页显示数" + pageSize);

        LambdaQueryWrapper<DishFlavor> wrapper = new LambdaQueryWrapper<>();
        wrapper.isNull(DishFlavor::getDishId);
        wrapper.eq(name != "", DishFlavor::getName, name);
        wrapper.orderByDesc(DishFlavor::getUpdateTime);
        //进行分页查询-可跟条件
        Page<DishFlavor> urf = dishFlavorMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
        System.out.println("数据为：" + urf.getRecords());
        System.out.println("总数为：" + urf.getTotal() + ",总页数为：" + urf.getPages());
        System.out.println("当前页为：" + urf.getCurrent() + ",每页限制：" + urf.getSize());
        return urf;
    }
}
